package bancosys.tec.rtm.impl.diagnostician;

import bancosys.tec.rtm.diagnostician.AbstractDiagnostician;
import bancosys.tec.rtm.diagnostician.DiagnosisBean;

/**
 * @author takeshi
 */
public class JavaVersionDiagnostician extends AbstractDiagnostician {

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return "Versão do Java";
    }

    /**
     * @param className String
     * @return boolean
     */
    private static boolean isClassPresent(String className) {
        try {
            Class.forName(className);
            return true;
        } catch (Throwable t) {
            return false;
        }
    }

    /**
     * {@inheritDoc}
     * 
     * @see bancosys.tec.rtm.diagnostician.AbstractDiagnostician#fillDiagnosisBean(bancosys.tec.rtm.diagnostician.DiagnosisBean)
     */
    @Override
    protected boolean fillDiagnosisBean(DiagnosisBean bean) throws Exception {
        bean.addDescription("JVM version: " + System.getProperty("java.version"));
        if (isClassPresent("javax.swing.GroupLayout")) {
            bean.addDescription("javax.swing.GroupLayout present");
        }
        if (isClassPresent("java.util.Deque")) {
            bean.addDescription("java.util.Deque<E> present");
        }
        if (isClassPresent("javax.ejb.EJB")) {
            bean.addDescription("JavaEE5 annotations present");
        }
        return true;
    }

}
